

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>rbdmap -- 在引导时映射 RBD 设备 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/doctools.js"></script>
        <script src="../../../_static/sphinx_highlight.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="ceph-rbdnamer -- 用于命名 RBD 设备的 udev 辅助程序" href="../ceph-rbdnamer/" />
    <link rel="prev" title="rbd-ggate -- 通过 FreeBSD GEOM 网关映射 rbd 映像" href="../rbd-ggate/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../../" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../../../rbd/">Ceph 块设备</a></li>
          <li class="breadcrumb-item"><a href="../../../rbd/man/">Ceph 块设备手册页</a></li>
      <li class="breadcrumb-item active">rbdmap -- 在引导时映射 RBD 设备</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../../../_sources/man/8/rbdmap.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../" class="icon icon-home"> Ceph
          

          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../../rbd/rados-rbd-cmds/">基本命令</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../rbd/rbd-operations/">运维</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../../rbd/rbd-integrations/">对接</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../../../rbd/man/">手册页</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../rbd/">rbd</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-fuse/">rbd-fuse</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-nbd/">rbd-nbd</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-ggate/">rbd-ggate</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">rbd-map</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id1">提纲</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id2">描述</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">实例</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id4">选项</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id5">使用范围</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id6">参考</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../ceph-rbdnamer/">ceph-rbdnamer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-replay-prep/">rbd-replay-prep</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-replay/">rbd-replay</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-replay-many/">rbd-replay-many</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../../rbd/api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../monitoring/">监控概览</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../hardware-monitoring/">硬件监控</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <section id="rbdmap-rbd">
<h1>rbdmap -- 在引导时映射 RBD 设备<a class="headerlink" href="#rbdmap-rbd" title="Permalink to this heading"></a></h1>
<section id="id1">
<h2>提纲<a class="headerlink" href="#id1" title="Permalink to this heading"></a></h2>
<div class="line-block">
<div class="line"><strong>rbdmap map</strong></div>
<div class="line"><strong>rbdmap unmap</strong></div>
</div>
</section>
<section id="id2">
<h2>描述<a class="headerlink" href="#id2" title="Permalink to this heading"></a></h2>
<p><strong>rbdmap</strong> 是个 shell 脚本，用于自动化一到多个 RBD (RADOS
Block Device) 映像的 <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">map</span></code> 和 <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">unmap</span></code> 操作，同时这个脚本也可以由系统管理员随时手动运行，但主要的用途还是把启动时 RBD 映像的映射、挂载（还有关机时的卸载、取消映射）操作自动化，由 init 系统（一个 systemd 的 unit 文件，为此
ceph-common 软件包打包了 <code class="docutils literal notranslate"><span class="pre">rbdmap.service</span></code> ）触发。</p>
<p>此脚本只需一个参数，可以是 map 或 unmap 。
运行时，脚本会分析配置文件（默认为 <code class="docutils literal notranslate"><span class="pre">/etc/ceph/rbdmap</span></code> ，
但可以用环境变量 <code class="docutils literal notranslate"><span class="pre">RBDMAPFILE</span></code> 覆盖），
配置文件的每行对应一个要映射、
或取消映射的 RBD 映像。</p>
<p>配置文件格式为：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">IMAGESPEC</span> <span class="n">RBDOPTS</span>
</pre></div>
</div>
<p>其中， <code class="docutils literal notranslate"><span class="pre">IMAGESPEC</span></code> 的格式应该是 <code class="docutils literal notranslate"><span class="pre">POOLNAME/IMAGENAME</span></code> （存储池名、一个斜线、和映像名），或只有 <code class="docutils literal notranslate"><span class="pre">IMAGENAME</span></code> ，此时
<code class="docutils literal notranslate"><span class="pre">POOLNAME</span></code> 默认为 rbd 。 <code class="docutils literal notranslate"><span class="pre">RBDOPTS</span></code> 是可选项列表，包含要传入底层 <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">map</span></code> 命令的参数，这些参数及其取值应该是逗号分隔的字符串：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">PARAM1</span><span class="o">=</span><span class="n">VAL1</span><span class="p">,</span><span class="n">PARAM2</span><span class="o">=</span><span class="n">VAL2</span><span class="p">,</span><span class="o">...</span><span class="p">,</span><span class="n">PARAMN</span><span class="o">=</span><span class="n">VALN</span>
</pre></div>
</div>
<p>此配置会让脚本执行如下的 <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">map</span></code> 命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rbd</span> <span class="nb">map</span> <span class="n">POOLNAME</span><span class="o">/</span><span class="n">IMAGENAME</span> <span class="o">--</span><span class="n">PARAM1</span> <span class="n">VAL1</span> <span class="o">--</span><span class="n">PARAM2</span> <span class="n">VAL2</span>
</pre></div>
</div>
<p>（ <code class="docutils literal notranslate"><span class="pre">rbd</span></code> 命令的可用选项请参考其手册页。）
对于包含逗号和等号的参数和数值，
可以加单引号来防止它们被替换。</p>
<p>运行 <code class="docutils literal notranslate"><span class="pre">rbdmap</span> <span class="pre">map</span></code> 时，此脚本先分析配置文件，对于每个配置了的 RBD 映像，首先尝试映射它（用 <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">map</span></code> 命令），然后，尝试挂载此映像。</p>
<p>运行 <code class="docutils literal notranslate"><span class="pre">rbdmap</span> <span class="pre">unmap</span></code> 时，罗列在配置文件内的映像会被依次卸载、取消映射。</p>
<p><code class="docutils literal notranslate"><span class="pre">rbdmap</span> <span class="pre">unmap-all</span></code> 尝试卸载、然后取消当前映射的所有 RBD 映像，不管它们是否在配置文件里。</p>
<p>如果操作成功， <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">map</span></code> 操作会把映像映射到类似
<code class="docutils literal notranslate"><span class="pre">/dev/rbdX</span></code> 的设备，此时，会触发 udev 规则来创建友好的设备名符号链接，如 <code class="docutils literal notranslate"><span class="pre">/dev/rbd/POOLNAME/IMAGENAME</span></code> ，链接到映射的真实设备。</p>
<p>挂载、卸载功能要正常运行的话，友好的设备名在 <code class="docutils literal notranslate"><span class="pre">/etc/fstab</span></code>
里面还必须有相应配置。</p>
<p>在 <code class="docutils literal notranslate"><span class="pre">/etc/fstab</span></code> 里面写 RBD 映像的配置条目时，最好加上
noauto （或者 nofail ）挂载选项。这样可防止 init 系统过早地挂载设备——甚至早于相应设备存在时。
（正因为 <code class="docutils literal notranslate"><span class="pre">rbdmap.service</span></code> 是执行 shell 脚本的，
所以在引导过程中都触发得很晚。）</p>
</section>
<section id="id3">
<h2>实例<a class="headerlink" href="#id3" title="Permalink to this heading"></a></h2>
<p>配置实例 <code class="docutils literal notranslate"><span class="pre">/etc/ceph/rbdmap</span></code> 内含三个 RBD 映像，分别名为
bar1 、 bar2 和 bar3 ，都在 foopool 存储池内：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">foopool</span><span class="o">/</span><span class="n">bar1</span>    <span class="nb">id</span><span class="o">=</span><span class="n">admin</span><span class="p">,</span><span class="n">keyring</span><span class="o">=/</span><span class="n">etc</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">ceph</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">keyring</span>
<span class="n">foopool</span><span class="o">/</span><span class="n">bar2</span>    <span class="nb">id</span><span class="o">=</span><span class="n">admin</span><span class="p">,</span><span class="n">keyring</span><span class="o">=/</span><span class="n">etc</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">ceph</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">keyring</span>
<span class="n">foopool</span><span class="o">/</span><span class="n">bar3</span>    <span class="nb">id</span><span class="o">=</span><span class="n">admin</span><span class="p">,</span><span class="n">keyring</span><span class="o">=/</span><span class="n">etc</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">ceph</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">keyring</span><span class="p">,</span><span class="n">options</span><span class="o">=</span><span class="s1">&#39;lock_on_read,queue_depth=1024&#39;</span>
</pre></div>
</div>
<p>此文件的每一行都有两种字符串：映像说明、
和传递给 <code class="docutils literal notranslate"><span class="pre">rbd</span> <span class="pre">map</span></code> 的选项。这两行将被转换为如下的命令：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rbd</span> <span class="nb">map</span> <span class="n">foopool</span><span class="o">/</span><span class="n">bar1</span> <span class="o">--</span><span class="nb">id</span> <span class="n">admin</span> <span class="o">--</span><span class="n">keyring</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">ceph</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">keyring</span>
<span class="n">rbd</span> <span class="nb">map</span> <span class="n">foopool</span><span class="o">/</span><span class="n">bar2</span> <span class="o">--</span><span class="nb">id</span> <span class="n">admin</span> <span class="o">--</span><span class="n">keyring</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">ceph</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">keyring</span>
<span class="n">rbd</span> <span class="nb">map</span> <span class="n">foopool</span><span class="o">/</span><span class="n">bar2</span> <span class="o">--</span><span class="nb">id</span> <span class="n">admin</span> <span class="o">--</span><span class="n">keyring</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">ceph</span><span class="o">/</span><span class="n">ceph</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">admin</span><span class="o">.</span><span class="n">keyring</span> <span class="o">--</span><span class="n">options</span> <span class="n">lock_on_read</span><span class="p">,</span><span class="n">queue_depth</span><span class="o">=</span><span class="mi">1024</span>
</pre></div>
</div>
<p>假设这些映像上的文件系统为 XFS ，
其对应的 <code class="docutils literal notranslate"><span class="pre">/etc/fstab</span></code> 配置可能如下：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">rbd</span><span class="o">/</span><span class="n">foopool</span><span class="o">/</span><span class="n">bar1</span> <span class="o">/</span><span class="n">mnt</span><span class="o">/</span><span class="n">bar1</span> <span class="n">xfs</span> <span class="n">noauto</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">rbd</span><span class="o">/</span><span class="n">foopool</span><span class="o">/</span><span class="n">bar2</span> <span class="o">/</span><span class="n">mnt</span><span class="o">/</span><span class="n">bar2</span> <span class="n">xfs</span> <span class="n">noauto</span> <span class="mi">0</span> <span class="mi">0</span>
<span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">rbd</span><span class="o">/</span><span class="n">foopool</span><span class="o">/</span><span class="n">bar3</span> <span class="o">/</span><span class="n">mnt</span><span class="o">/</span><span class="n">bar3</span> <span class="n">xfs</span> <span class="n">noauto</span> <span class="mi">0</span> <span class="mi">0</span>
</pre></div>
</div>
<p>创建好映像、并写好 <code class="docutils literal notranslate"><span class="pre">/etc/ceph/rbdmap</span></code> 配置文件后，
只需启用这个 unit 就可让映像在启动时自动映射和挂载：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">systemctl</span> <span class="n">enable</span> <span class="n">rbdmap</span><span class="o">.</span><span class="n">service</span>
</pre></div>
</div>
</section>
<section id="id4">
<h2>选项<a class="headerlink" href="#id4" title="Permalink to this heading"></a></h2>
<p>无</p>
</section>
<section id="id5">
<h2>使用范围<a class="headerlink" href="#id5" title="Permalink to this heading"></a></h2>
<p><strong>rbdmap</strong> 是 Ceph 的一部分，这是个伸缩力强、开源、分布式的存储系统，更多信息参见 <a class="reference external" href="https://docs.ceph.com">https://docs.ceph.com</a> 。</p>
</section>
<section id="id6">
<h2>参考<a class="headerlink" href="#id6" title="Permalink to this heading"></a></h2>
<p><a class="reference internal" href="../rbd/"><span class="doc">rbd</span></a>(8),</p>
</section>
</section>



<div id="support-the-ceph-foundation" class="admonition note">
  <p class="first admonition-title">Brought to you by the Ceph Foundation</p>
  <p class="last">The Ceph Documentation is a community resource funded and hosted by the non-profit <a href="https://ceph.io/en/foundation/">Ceph Foundation</a>. If you would like to support this and our other efforts, please consider <a href="https://ceph.io/en/foundation/join/">joining now</a>.</p>
</div>


           </div>
           
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="../rbd-ggate/" class="btn btn-neutral float-left" title="rbd-ggate -- 通过 FreeBSD GEOM 网关映射 rbd 映像" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../ceph-rbdnamer/" class="btn btn-neutral float-right" title="ceph-rbdnamer -- 用于命名 RBD 设备的 udev 辅助程序" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).</p>
  </div>

   

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>